package br.usp.ime.protoc.neuroimagem;

import java.util.HashSet;
import java.util.Iterator;

import com.google.gwt.user.client.rpc.IsSerializable;

import br.usp.ime.protoc.fujaba.FEmptyIterator;

public class Projeto implements IsSerializable
{
   private String descricao;

   public String getDescricao()
   {
      return this.descricao;
   }

   public void setDescricao(String value)
   {
      if (this.descricao != value)
      {
         
         this.descricao = value;
         
      }
   }

   /**
    * <pre>
    *          1     has     1..* 
    * Projeto -------------------- Exame
    *          projeto      exame 
    * </pre>
    */
   private HashSet exame;

   public boolean addToExame(Exame value)
   {
      boolean changed = false;
      if (value != null)
      {
         if (this.exame == null)
         {
            this.exame = new HashSet (); // or FTreeSet () or FLinkedList ()
         }
         
         changed = this.exame.add (value);
         if (changed)
         {
            value.setProjeto (this);
         }
         
      }
      return changed;
   }

   public boolean hasInExame(Exame value)
   {
      return ((this.exame != null) &&
              (value != null) &&
              this.exame.contains (value));
   }

   public Iterator iteratorOfExame()
   {
      return ((this.exame == null)
              ? FEmptyIterator.get ()
              : this.exame.iterator ());
   }

   public void removeAllFromExame()
   {
      Exame tmpValue;
      Iterator iter = this.iteratorOfExame ();
      while (iter.hasNext ())
      {
         tmpValue = (Exame) iter.next ();
         this.removeFromExame (tmpValue);
      }
   }

   public boolean removeFromExame(Exame value)
   {
      boolean changed = false;
      if ((this.exame != null) && (value != null))
      {
         
         changed = this.exame.remove (value);
         if (changed)
         {
            value.setProjeto (null);
         }
         
      }
      return changed;
   }

   public int sizeOfExame()
   {
      return ((this.exame == null)
              ? 0
              : this.exame.size ());
   }

   public void removeYou()
   {
      removeAllFromExame ();
   }

}
